package com.htsk.city.services.wechat.vo;

import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil;
import com.htsk.city.services.core.domain.Post;
import com.htsk.city.services.core.domain.Topic;
import lombok.Data;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.List;

@Data
public class PostVO {
    private Long id;
    private String content;
    private List<String> images;
    private String location;
    private BigDecimal distance;
    private Integer likeCount;
    private Integer commentCount;
    private Integer browseCount;
    private String createdAt;
    private UserInfoVO userInfo;
    private List<Topic>  topics;
    private boolean isLike;

    public PostVO(Post post,UserInfoVO userInfo,List<Topic> topics,BigDecimal distance,Boolean isLike){
        this.id=post.getId();
        this.content=post.getContent();
        this.location=post.getLocation();
        this.likeCount=post.getLikeCount();
        this.commentCount=post.getCommentCount();
        this.browseCount=post.getBrowseCount();
        this.images= JSONUtil.toList(post.getImages(),String.class);
        this.createdAt= DateUtil.formatDateTime(post.getCreatedAt());
        this.userInfo=userInfo;
        this.topics=topics;
        this.distance=distance.setScale(2, RoundingMode.HALF_UP);
        this.isLike=isLike;
    }

}
